import java.io.*;

public class IoExample {
    public static void main(String[] args) {
        try {
            // 创建具体组件: FileInputStream
            InputStream fileInputStream = IoExample.class.getClassLoader()
                    .getResourceAsStream("example.txt");
            if (fileInputStream == null) {
                System.out.println("无法找到资源文件 example.txt");
                return;
            }
            
            // 使用装饰器: BufferedInputStream 添加缓冲功能
            InputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
            
            // 读取数据
            int data;
            while ((data = bufferedInputStream.read()) != -1) {
                System.out.print((char) data);
            }
            
            // 关闭流
            bufferedInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}